package com.justnow.offer;

import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;

/**
 * @author justnow
 * Created on 2020-09-16
 * Description
 */
public class Dianxin03 {
    static LinkedList<Integer> list = new LinkedList<>();
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        scanner.nextLine();
        for (int i = 0; i < n; i++) {
            String str = scanner.nextLine();
            Op(str);
        }
    }

    public static void Op(String str) {
        String[] s = str.split(" ");
        if (s.length == 1) {
            if (s[0].equals("pop")) {
                list.removeLast();
            }
            if (s[0].equals("top")) {
                Integer last = list.getLast();
                System.out.println(last);
            }
            if (s[0].equals("getMin")) {
                LinkedList<Integer> temp = new LinkedList<>(list);
                Collections.sort(temp);
                System.out.println(temp.getFirst());
            }
        } else {
            int val = Integer.valueOf(s[1]);
            list.addLast(val);
        }
    }
}
